<?php
/**
 * Created by PhpStorm.
 * User: rui
 * Date: 2018/11/27
 * Time: 17:40
 */

namespace App\Http\Resources;

use Illuminate\Support\Facades\Auth;

class TransferResource extends Resource
{
    public function toArray($request)
    {
        if ($this->from_user_id == Auth::id()) { // 转出记录
            $other_user = $this->toUser;
            $number = (string)-$this->number;
        } else { // 转入记录
            $other_user = $this->fromUser;
            $number = (string)$this->number;
        }

        return [
            'other_username' => $other_user->username,
            'number' => $number,
            'time' => $this->time,
        ];
    }
}